package com.wz.vavr;

import io.vavr.Tuple;
import io.vavr.Tuple2;
import io.vavr.control.Try;

import java.util.function.Function;

/**
 * Created by Administrator on 2020/5/26/026.
 */
public class VavrTest {

    static int divide(int dividend, int divisor) {
        // 如果除数为0，会产生异常
        return dividend / divisor;
    }

    static Try<Integer> safeDivide(Integer dividend, Integer divisor, FunctionTest ft) {
        System.out.println(ft.test(1));
        return Try.of(() -> divide(dividend, divisor)).onFailure(throwable -> System.out.println("----" + throwable + " error"));
    }

    void TestTuple() {
        Tuple2<String, String> people = Tuple.of("liu", "zhang");
        String name1 = people._1;
        String name2 = people._2;
    }

    public static class FuncTest{

        FuncTest(){
            System.out.println("gou zao1");
        }

        FuncTest(int i){
            System.out.println("gou zao2");
        }

        static FuncTest test1(int value){
            return new FuncTest();
        }

        FuncTest test2(int value){
            return new FuncTest();
        }

        @Override
        public String toString() {
            return "FuncTest";
        }
    }

    public static void main(String[] args) {
        safeDivide(1, 0, FuncTest::test1);
    }
}